using UniversalAdmin.Application.Dto;
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using UniversalAdmin.Application.Commands;
using Microsoft.AspNetCore.Http;

namespace UniversalAdmin.Application.Services;

/// <summary>
/// 用户服务接口
/// </summary>
public interface IAppUserServices
{
    /// <summary>
    /// 获取所有用户
    /// </summary>
    /// <returns>用户DTO集合</returns>
    Task<ApiResult<PagedResult<UserDto>>> GetPagedAsync(PagedQuery query);
    Task<ApiResult<IEnumerable<UserDto>>> GetAllAsync(string? search = null);

    /// <summary>
    /// 根据ID获取用户
    /// </summary>
    /// <param name="id">用户ID</param>
    /// <returns>用户DTO</returns>
    Task<ApiResult<UserDto>> GetByIdAsync(Guid id);

    /// <summary>
    /// 创建用户
    /// </summary>
    /// <param name="dto">创建用户DTO</param>
    /// <returns>任务</returns>
    Task<ApiResult> CreateAsync(CreateUserDto dto);

    /// <summary>
    /// 更新用户
    /// </summary>
    /// <param name="id">用户ID</param>
    /// <param name="dto">更新用户DTO</param>
    /// <param name="currentUserId">当前操作用户ID（用于权限验证）</param>
    /// <returns>任务</returns>
    Task<ApiResult> UpdateAsync(Guid id, UpdateUserDto dto, Guid? currentUserId = null);

    /// <summary>
    /// 删除用户
    /// </summary>
    /// <param name="id">用户ID</param>
    /// <param name="currentUserId">当前操作用户ID（用于防止删除自己）</param>
    /// <returns>任务</returns>
    Task<ApiResult> DeleteAsync(Guid id, Guid? currentUserId = null);

    /// <summary>
    /// 禁用用户
    /// </summary>
    /// <param name="userId">用户ID</param>
    /// <param name="currentUserId">当前操作用户ID（用于防止禁用自己）</param>
    /// <returns>任务</returns>
    Task<ApiResult> DisableAsync(Guid userId, Guid? currentUserId = null);

    /// <summary>
    /// 启用用户
    /// </summary>
    /// <param name="userId">用户ID</param>
    /// <returns>任务</returns>
    Task<ApiResult> EnableAsync(Guid userId);

    /// <summary>
    /// 重置密码
    /// </summary>
    /// <param name="userId">用户ID</param>
    /// <param name="dto">修改密码DTO</param>
    /// <param name="currentUserId">当前操作用户ID（用于权限验证）</param>
    /// <returns>任务</returns>
    Task<ApiResult> ChangePasswordAsync(Guid userId, ChangePasswordDto dto, Guid? currentUserId = null);

    /// <summary>
    /// 上传用户头像
    /// </summary>
    /// <param name="userId">用户ID</param>
    /// <param name="file">头像文件</param>
    /// <param name="currentUserId">当前操作用户ID（用于权限验证）</param>
    /// <returns>任务</returns>
    Task<ApiResult> UploadAvatarAsync(Guid userId, IFormFile file, Guid? currentUserId = null);

    /// <summary>
    /// 获取用户角色
    /// </summary>
    /// <param name="userId">用户ID</param>
    /// <returns>角色名称集合</returns>
    Task<IEnumerable<string>> GetUserRolesAsync(Guid userId);

    /// <summary>
    /// 获取用户角色详细信息
    /// </summary>
    /// <param name="userId">用户ID</param>
    /// <returns>角色详细信息集合</returns>
    Task<IEnumerable<RoleDto>> GetUserRolesDetailAsync(Guid userId);

    /// <summary>
    /// 分配角色
    /// </summary>
    /// <param name="userId">用户ID</param>
    /// <param name="roleIds">角色ID集合</param>
    /// <returns>任务</returns>
    Task<ApiResult> AssignRolesAsync(Guid userId, List<Guid> roleIds);

    /// <summary>
    /// 检查用户是否有指定权限
    /// </summary>
    /// <param name="userId">用户ID</param>
    /// <param name="permissionCode">权限编码</param>
    /// <returns>是否有权限</returns>
    Task<bool> HasPermissionAsync(Guid userId, string permissionCode);

    /// <summary>
    /// 获取用户的所有权限
    /// </summary>
    /// <param name="userId">用户ID</param>
    /// <returns>权限编码集合</returns>
    Task<IEnumerable<string>> GetUserPermissionsAsync(Guid userId);
}